import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter)

import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'

export default new VueRouter({
    mode:'hash',
    routes:[
        {
            path:'/home',
            component:Home,
        },
        {
            name:'search',
            // path:'/search/:keyword', //必传
            path:'/search/:keyword?', //非必传
            component:Search,
            // props:true, //传params参数
            // props:{text:'1234'}, //传新值
            props:(route)=>{
                return {
                    keyword: route.params.keyword,
                    keyword1: route.query.keyword1,
                }
            }
        },
        {
            name:'detail',
            path:'/detail/:skuId',
            component:Detail
        },
        {
            caseSensitive:true,
            path:'/addCartSuccess/:skuNum',
            component:AddCartSuccess,
        },
        {
            path:'/shopcart',
            component:ShopCart
        },
        {
            path:'/login',
            component:Login,
            meta:{
                isHide:true
            }
        },
        {
            path:'/register',
            component:Register,
            meta:{
                isHide:true
            }
        },
        {
            path:'/',
            redirect:'/home'
        }
    ],
    scrollBehavior(to,from,savedPosition){
        // return 期望滚动到哪个的位置
        //      x 代表水平滚动 y代表垂直滚动  值的单位是px
        // return { x: number, y: number }
        return {y:50}
    }
})